<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    .layui-input-block{
        margin-left: 90px;
    }
</style>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">投放管理</a>
            <a><cite>按负责人统计</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">

        <form class="layui-form layui-row" style="margin-top:15px;margin-bottom: 10px;" lay-filter="searchForm">
            <div class="layui-inline" id="dataTime">
                <label class="layui-form-label w-auto">日期：</label>
                <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                    <div class="layui-input-inline" style="margin-right:10px">
                        <input type="text" class="layui-input" name="start_date" id="start_time" autocomplete="off"
                            placeholder="开始时间">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_date" id="end_time" autocomplete="off"
                            placeholder="结束日期">
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">负责人：</label>
                <div id="responsibilityPerson"></div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">公司：</label>
                <div id="pMenu2"></div>
            </div>

            <div class="layui-inline" style="margin-left:10px">
                <button class="layui-btn" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
        <table id="launchDataList" lay-filter="launchDataList"></table>
    </div>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="look_month">按月份查看</a>
        <!-- <a class="layui-btn layui-btn-xs" lay-event="look">查看</a> -->
    </script>
    <script>
        layui.use(['table', "form", "layer", 'laydate'], function () {
            var table = layui.table
                form = layui.form,
                laydate = layui.laydate,
                layer = layui.layer;
            // 日期
            laydate.render({
                elem: '#time',
                range: ['#start_time', '#end_time'],
                format: 'yyyy-MM-dd'
            });
            let params = {
                elem: '#launchDataList'
                , url: `/admin/launch/byPeopleList` //数据接口
                , id: 'launchDataList'
                , page:false
                , totalRow: true
                , height:'full-140'
                , cols: [[ //表头
                    { field: 'name', title: '负责人', align: 'center', width: 135, totalRowText: '总合计：' }
                    , { field: 'cost', title: '消耗<i class="layui-icon iconfont icon-lytishi1" id="cost"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 120}
                    , { field: 'actual_cost', title: '实际消耗<i class="layui-icon iconfont icon-lytishi1" id="actual_cost"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 120 }
                    , { field: 'register_user_num', title: '注册用户数', align: 'center', totalRow: '{{= d.TOTAL_NUMS }}', sort:true , width:120}
                    , { field: 'activation_user_num', title: '激活用户数<i class="layui-icon iconfont icon-lytishi1" id="activation_user_num"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS }}', sort:true, width:130 }
                    , { field: 'current_recharge', title: '充值<i class="layui-icon iconfont icon-lytishi1" id="current_recharge"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 120 }
                    , { field: 'total_recharge', title: '累计充值<i class="layui-icon iconfont icon-lytishi1" id="total_recharge_tips"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}' , sort:true, width: 120 }
                    , { field: 'current_recharge_discount', title: '收益<i class="layui-icon iconfont icon-lytishi1" id="current_recharge_discount"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 120 }
                    , { field: 'total_income', title: '累计收益<i class="layui-icon iconfont icon-lytishi1" id="total_income_tips"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}' , sort:true, width: 120 }
                    , { field: 'current_recharge_profit', title: '利润<i class="layui-icon iconfont icon-lytishi1" id="current_recharge_profit"></i>', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 120 }
                    , { field: 'current_recovery', title: '返后ROI<i class="layui-icon iconfont icon-lytishi1" id="current_recovery"></i>', align: 'center' }
                    
                    
                    , { field: 'total_recovery', title: '累计ROI<i class="layui-icon iconfont icon-lytishi1" id="total_recovery"></i>', align: 'center'}
                    , { field: 'recharge_number', title: '订单数', width: 100, align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed() }}', sort:true }
                    , { field: 'conversion_number', title: '充值人数<i class="layui-icon iconfont icon-lytishi1" id="recharge_user_num"></i>',width:120, align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed() }}', sort:true }
                    // , { field: 'revenue', title: '营收情况', align: 'center', totalRow: '{{= d.TOTAL_NUMS.toFixed(2) }}', sort:true, width: 115 }
                    , { field: 'per_capita_contribution', title: '人均充值<i class="layui-icon iconfont icon-lytishi1" id="per_capita_contribution"></i>', width:120, align: 'center', sort:true }
                    , { toolbar: '#tbBar', title: '操作', align: 'center', width: 110 }

                ]],
                done: function (res, curr, count) {
                    const cost = this.elem.next().find('.layui-table-total td[data-field="cost"] .layui-table-cell').text(); // 花费
                    const actual_cost = this.elem.next().find('.layui-table-total td[data-field="actual_cost"] .layui-table-cell').text(); // 实际花费
                    const current_recharge = this.elem.next().find('.layui-table-total td[data-field="current_recharge"] .layui-table-cell').text(); // 当天充值
                    const total_recharge = this.elem.next().find('.layui-table-total td[data-field="total_recharge"] .layui-table-cell').text(); // 累计充值
                    const total_income = this.elem.next().find('.layui-table-total td[data-field="total_income"] .layui-table-cell').text(); // 累计收益
                    const current_recharge_discount = this.elem.next().find('.layui-table-total td[data-field="current_recharge_discount"] .layui-table-cell').text();
                    const current_recovery = Percentage(current_recharge_discount, actual_cost);//当天回收=当天充值/花费
                    const total_recovery = Percentage(total_income, actual_cost);//累计回收=累计充值/花费

                    const conversion_number = this.elem.next().find('.layui-table-total td[data-field="conversion_number"] .layui-table-cell').text(); // 充值人数
                    const per_capita_contribution = perCapita(total_recharge, conversion_number); // 充值用户贡献 = 累计充值 / 充值人数

                    this.elem.next().find('.layui-table-total td[data-field="current_recovery"] .layui-table-cell').text(current_recovery + '%');
                    this.elem.next().find('.layui-table-total td[data-field="total_recovery"] .layui-table-cell').text(total_recovery + '%');
                    this.elem.next().find('.layui-table-total td[data-field="per_capita_contribution"] .layui-table-cell').text(per_capita_contribution);

                    tips('#cost', '#cost', '扣除返点前的花费')
                    tips('#actual_cost', '#actual_cost', '扣除返点后的花费')
                    tips('#activation_user_num', '#activation_user_num', '今日从推广链接进入的用户数')
                    tips('#current_recharge', '#current_recharge', '该剧每日当天充值总和')
                    tips('#current_recharge_discount', '#current_recharge_discount', '该剧每日当天营收总和（充值打9折）')
                    tips('#current_recharge_profit', '#current_recharge_profit', '累计收益-实际消耗')
                    tips('#current_recovery', '#current_recovery', '收益除以实际消耗的百分比')
                    tips('#total_recharge_tips','#total_recharge_tips','当日激活的用户在当天以及后续的累计充值')
                    tips('#total_income_tips','#total_income_tips','累计充值*0.9（2023年8月21号前是当天充值*0.95）')
                    tips('#total_recovery','#total_recovery','累计收益除以实际消耗的百分比')
                    tips('#per_capita_contribution','#per_capita_contribution','充值用户的人均充值')
                    tips('#recharge_user_num','#recharge_user_num','当日激活人数的充值人数')
                }
            };
            tableList(params)
            $('#resetList').on('click', function () {
                table.reload('launchDataList', { where: {} })
                selectN(selectParams1)
            });
            table.on('tool(launchDataList)', function (obj) {
                var event = obj.event;
                if (event === 'look') {
                    let searchFormVal = form.val("searchForm");
                    if(!searchFormVal.start_date && !searchFormVal.end_date){
                        layer.msg('请先选择日期！',{icon:5,time:2000});
                        return;
                    }
                    x_admin_show('查看', `./peopleIndex.html?responsibility_person_id=${obj.data.id}&start_date=${searchFormVal.start_date}&end_date=${searchFormVal.end_date}`, 1400, 600, null);
                }else if(event === 'look_month'){
                    x_admin_show('按月份查看', `./peopleInfo.html?id=${obj.data.id}`, 1500, 730, null);
                }
            });
        })

        let selectParams1 = {
            url: '/admin/responsibilityPerson/select?type=1',
            elem: '#responsibilityPerson',
            selected: [],
            tips: '选择负责人',
            name: 'responsibility_person_id',
            field_id: 'responsibility_person_id',
            field_Name: 'responsibility_person_name',
        }
        selectN(selectParams1)
        let selectParams2 = {
            url: '/admin/company/select?type=1',
            selected: [],
            tips: '选择公司',
            name: 'company_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu2'
        }
        selectN(selectParams2)
    </script>
</body>

</html>